#! /bin/bash
pull_page=1
commit_page=1
issue_page=1
PULL=`curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${1}/pulls?state=all&per_page=100&page=${pull_page}" | jq --arg one_month_ago "$(date -u --date='-3 month' '+%Y-%m-%dT%H:%M:%SZ')" '[.[] | select(.created_at >= $one_month_ago) | {created_at, title}] | length'`
COMMIT=`curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${1}/commits?per_page=100&page=${commit_page}&since=$(date -u --date='-3 month' '+%Y-%m-%dT%H:%M:%SZ')" | jq '[.[] | {url: .html_url, message: .commit.message, date: .commit.committer.date}] | length'`
ISSUE=`curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${1}/issues?per_page=100&state=all&page=${issue_page}&since=$(date -u --date='-3 month' '+%Y-%m-%dT%H:%M:%SZ')" | jq '[.[] |  {url, title, created_at}] | length'`
while(( $PULL==100 ))
do
    pull_page=`expr $pull_page + 1`
    PULL=`curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${1}/pulls?state=all&per_page=100&page=${pull_page}" | jq --arg one_month_ago "$(date -u --date='-3 month' '+%Y-%m-%dT%H:%M:%SZ')" '[.[] | select(.created_at >= $one_month_ago) | {created_at, title}] | length'`
done
PULL=`expr $PULL + 100 \* \( $pull_page - 1 \)`

while(( $COMMIT==100 ))
do
    commit_page=`expr $commit_page + 1`
    COMMIT=`curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${1}/commits?per_page=100&page=${commit_page}&since=$(date -u --date='-3 month' '+%Y-%m-%dT%H:%M:%SZ')" | jq '[.[] | {url: .html_url, message: .commit.message, date: .commit.committer.date}] | length'`
done
COMMIT=`expr $COMMIT + 100 \* \( $commit_page - 1 \)`


while(( $ISSUE==100 ))
do
    issue_page=`expr $issue_page + 1` 
    ISSUE=`curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${1}/issues?per_page=100&state=all&page=${issue_page}&since=$(date -u --date='-3 month' '+%Y-%m-%dT%H:%M:%SZ')" | jq '[.[] |  {url, title, created_at}] | length'`
done
ISSUE=`expr $ISSUE + 100 \* \( $issue_page - 1 \)`


echo "https://github.com/${1} : pull requst number: ${PULL} , commit number: ${COMMIT} , issue number: ${ISSUE}"